using UnityEngine;

public class CRGate : Mortal
{
	public GameObject[] closedDate;

	public GameObject opendGate;

	private Quaternion initialRotation;

	private Transform _parent;

	public bool opend;

	public override void Awake()
	{
		OpenGate(false);
		initialRotation = base.transform.localRotation;
		_parent = base.transform.parent;
		base.Awake();
	}

	public override void Respawn()
	{
		base.photonView.RPC("RespawnCRGateRPC", PhotonTargets.All);
	}

	[PunRPC]
	public virtual void RespawnCRGateRPC()
	{
		base.Respawn(base.transform.position);
		base.transform.parent = _parent;
		base.transform.localRotation = initialRotation;
		OpenGate(false);
	}

	public override void GetDamage(int damage, int damageType, int iKillerId, Vector3 positionKiller, Vector3? hitPoint = null)
	{
		if ((iKillerId != PlayerBehavior.MyPlayer.viewId || TDMController.myTeam != PunTeams.Team.red || ((CopsRobbersSettings)settings.GetSettings(TypeGame.CopsAndRobbers)).friendlyFire) && PVPManager.instance.gameIsStarted)
		{
			base.GetDamage(damage, damageType, iKillerId, positionKiller, hitPoint);
			CopsAndRobbersInterface.instance.GateDamaged(health);
			CopsAndRobbersInterface.instance.ShowGateDamaged();
		}
	}

	public override void Kill(int iKillerId = -9999)
	{
		base.Kill();
		OpenGate(true);
		CopsAndRobbersController.instance.gatesDestroyed++;
		int currentStage = CopsAndRobbersController.instance.GetCurrentStage();
		CopsAndRobbersInterface.instance.GateDestroyed(currentStage - 1);
		CopsAndRobbersInterface.instance.ChangeFloatingPoint();
		StartCoroutine(CopsAndRobbersInterface.instance.ShowNotification(TDMController.myTeam, currentStage, 5f));
		if (CopsAndRobbersController.instance.GetCurrentStage() < 0)
		{
			CopsAndRobbersController.instance.FinishGame();
		}
	}

	public void OpenGate(bool open)
	{
		if (opend != open)
		{
			opend = open;
			if (opendGate != null)
			{
				opendGate.SetActive(open);
			}
			GameObject[] array = closedDate;
			foreach (GameObject gameObject in array)
			{
				gameObject.SetActive(!open);
			}
		}
	}
}
